package udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UdpClient {

	public static void main(String[] args) throws Exception{
		String msg="I am johnYu!";
		DatagramPacket p=new DatagramPacket(msg.getBytes("UTF-8"), 0, msg.length(), InetAddress.getByName("127.0.0.1"), 8888);
		DatagramSocket sk=new DatagramSocket();
		
		sk.send(p);
		byte[] buf=new byte[256];
		DatagramPacket  p1=new DatagramPacket(buf, 256);
		sk.receive(p1);
		String rec=new String(p1.getData(),0,p1.getLength());
		System.out.println(rec);
		
		sk.close();

	}

}
